/**
 * @file Miscellaneous.h
 * @author your name (you@domain.com)
 * @brief 
 * @version 0.1
 * @date 2020-10-19
 * 
 * @copyright Copyright (c) 2020
 * 
 */

#ifndef _Miscellaneous_h
#define _Miscellaneous_h
#include <cmath>
    ///for 2D case;
    int index_j(int current_index , int l){return current_index / int(pow(2,l) + 1);};
    int index_i(int cuurent_index , int l){return cuurent_index % int(pow(2,l) + 1);};
    int index(int i,int j,int l){return i + j * (pow(2,l) + 1);}; 
    bool isboundary(int i,int l)
    {
        double h = 1 / double(pow(2,l));
        return (index_j(i,l) * h == 0) || (index_i(i,l) * h == 0) || (index_i(i,l) * h == 1) || (index_j(i,l) * h == 1);
    }
    //范数
    double norm_2(std::vector<double> x,double h)
    {
        double sum = 0.0;
        for(int i = 0; i < x.size();i++)
        {
            sum += x[i]*x[i];
        }
        return std::sqrt(h * sum);
    }
    double norm_max(std::vector<double> x)
    {
        double ans = 0.0;
        for(int i = 0; i < x.size();i++)
        {
            ans = std::max(ans,fabs(x[i]));
        }
        return ans;
    }

#else 
#endif